import api from './api';
let oApi = new api();
export function shareInit(options){
    oApi.getSignature(res=>{
        if (res.code === 1) {
            wx.config({
                debug: false,
                appId: "wxbc0aa7e422298706",
                timestamp: res.data.timestamp,
                nonceStr: res.data.noncestr,
                signature: res.data.signature,
                jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo', 'onMenuShareQZone']
            })
            var title = options.title;
            var desc = options.desc;
            var links = window.location.href;
            var imgUrl = options.img;
            wx.ready(function() {
                wx.onMenuShareTimeline({
                    title: title, // 分享标题
                    desc: desc, // 分享描述
                    link: links, // 分享链接
                    imgUrl: imgUrl, // 分享图标
                    success: function() {

                    },
                    cancel: function() {

                    }
                });
                wx.onMenuShareAppMessage({
                    title: title, // 分享标题
                    desc: desc, // 分享描述
                    link: links, // 分享链接
                    imgUrl: imgUrl, // 分享图标
                    success: function() {

                    },
                    cancel: function() {

                    }
                });
                wx.onMenuShareQQ({
                    title: title, // 分享标题
                    desc: desc, // 分享描述
                    link: links, // 分享链接
                    imgUrl: imgUrl, // 分享图标
                    success: function() {

                    },
                    cancel: function() {

                    }
                });
                wx.onMenuShareWeibo({
                    title: title, // 分享标题
                    desc: desc, // 分享描述
                    link: links, // 分享链接
                    imgUrl: imgUrl, // 分享图标
                    success: function() {

                    },
                    cancel: function() {

                    }
                });
                wx.onMenuShareQZone({
                    title: title, // 分享标题
                    desc: desc, // 分享描述
                    link: links, // 分享链接
                    imgUrl: imgUrl, // 分享图标
                    success: function() {

                    },
                    cancel: function() {}
                });

            });
            wx.error(function(err) {
                alert(JSON.stringify(err))
            });
        } else {
            // eslint-disable-next-line no-console
            console.log("获取微信签名失败");
        }
    },err=>{
        // eslint-disable-next-line no-console
        console.log(err);
    });
}